home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacGames Sampler
/
PHT MacGames Bundle.iso
/
MacSource Folder
/
Samples from the CD
/
C and C++
/
Gnuplot 3.5 for Macintosh
/
SOURCES 3.5
/
term
/
metafont.trm
< prev
next >
Wrap
Text File
|
1993-11-03
|
15KB
|
419 lines
/*
* $Id: metafont.trm%v 3.50 1993/07/09 05:35:24 woo Exp $
*/
/*
* GNUPLOT -- mf.trm
*
* This terminal driver supports:
* Metafont Plot Commands
*
* Written by : Pl Hedne
* Trondheim, Norway
* Pal.Hedne@termo.unit.no
*/
/*
* Improvements and bug fixes by Carsten Steger:
* - Set default plot size to 5 by 3 inches as in the latex- and eepic-
* drivers
* - Fixed some bugs concerning resolution dependent output
* - Added MF_scale function
* - Added MF_justify_text function and modified MF_put_text function and
* put_text macro accordingly
* - Modified MF_move and MF_vector to make output shorter and modified
* MF_text accordingly
* - Added various linetypes by plotting dashed lines; had to modify
* MF_linetype and MF_vector for this
* - Added MF_arrow function
* - All global variables and #define'd names begin with MF_ now
* As a consequence almost nothing of the original code by Pl Hedne remains
* but credit goes to him for the ingenious trick of storing the character
* images into picture variables, without which this driver would have been
* impossible for me to write.
*/
#define MF_DPI (300)
/* resolution of printer we expect to use; the value itself is not
* particularly important... it is here only for compatibility to the
* LaTeX-driver and to get the spacing right. */
/* 5 inches wide by 3 inches high (default) */
#define MF_XSIZE 5.0
#define MF_YSIZE 3.0
#define MF_XMAX (MF_XSIZE*MF_DPI)
#define MF_YMAX (MF_YSIZE*MF_DPI)
#define MF_HTIC (5*MF_DPI/72)
#define MF_VTIC (5*MF_DPI/72)
#define MF_HCHAR (MF_DPI*53/10/72)
#define MF_VCHAR (MF_DPI*11/72)
/* Plot size in inches */
static double MF_xsize = MF_XSIZE;
static double MF_ysize = MF_YSIZE;
static int MF_char_code;
static int MF_ang;
static int MF_line_type;
static enum JUSTIFY MF_justify;
static double MF_dist_left;
static int MF_is_solid;
static int MF_picked_up_pen;
/*
* We keep track of where we are with respect to dashed lines by using
* the next five variables. MF_dash_index indicates which element of
* MF_lines[..].dashlen should be used. The MF_last.. variables keep
* track of the position of the pen.
*/
static int MF_dash_index;
static unsigned int MF_last_x, MF_last_y;
static struct {
int solid; /* Is the line solid? */
float thickness; /* Thickness of pen we are going to use */
int dashlen[4]; /* Length of individual segments; even: line; odd: gap */
} MF_lines[10] = {
{1,1.5,0,0,0,0},
{0,1.0,MF_DPI/60,MF_DPI/50,MF_DPI/60,MF_DPI/50},
{1,1.5,0,0,0,0},
{0,1.5,MF_DPI/20,MF_DPI/30,MF_DPI/20,MF_DPI/30},
{0,1.5,MF_DPI/30,MF_DPI/20,MF_DPI/30,MF_DPI/20},
{0,1.5,MF_DPI/15,MF_DPI/30,MF_DPI/60,MF_DPI/30},
{0,1.5,MF_DPI/30,MF_DPI/50,MF_DPI/30,MF_DPI/50},
{0,1.5,MF_DPI/20,MF_DPI/50,MF_DPI/60,MF_DPI/30},
{0,1.5,MF_DPI/30,MF_DPI/50,MF_DPI/30,MF_DPI/30},
{0,1.5,MF_DPI/60,MF_DPI/50,MF_DPI/60,MF_DPI/30}
/* dash: line, gap, line, gap */
};
int MF_init ()
{
MF_char_code = 0;
MF_ang = 0;
fputs ("if unknown cmbase: input cmbase fi\n\n", outfile);
fputs ("tracingstats:=1;\n", outfile);
fputs ("picture r[];\n", outfile);
fputs ("\ndef openit = openwindow currentwindow\n", outfile);
fputs (" from (0,0) to (400,800) at (-50,500) enddef;\n", outfile);
fputs ("\nmode_setup;\n", outfile);
fputs ("\n%Include next eight lines if you have problems with the mode on your system..\n", outfile);
fputs ("%proofing:=0;\n", outfile);
fputs ("%fontmaking:=1;\n", outfile);
fputs ("%tracingtitles:=0;\n", outfile);
fputs ("%pixels_per_inch:=300;\n", outfile);
fputs ("%blacker:=0;\n", outfile);
fputs ("%fillin:=.2;\n", outfile);
fputs ("%o_correction:=.6;\n", outfile);
fputs ("%fix_units;\n", outfile);
/* Next lines must be included if text support is needed (CM base used) */
fputs ("\ndef put_text(expr ts,xstart,ystart,rot,justification) =\n", outfile);
fputs (" begingroup\n", outfile);
fputs (" text_width:=0;text_height:=0;\n", outfile);
fputs (" for ind:=0 step 1 until length(ts)-1:\n", outfile);
fputs (" dec_num:=ASCII substring (ind,ind+1) of ts;\n", outfile);
fputs (" if unknown r[dec_num]: dec_num:=32; fi\n", outfile);
fputs (" if dec_num=32: \n", outfile);
fputs (" text_width:=text_width+wd[65];\n", outfile);
fputs (" text_height:=max(text_height,ht[65]+dp[65]);\n", outfile);
fputs (" elseif dec_num>=0: \n", outfile);
fputs (" text_width:=text_width+wd[dec_num];\n", outfile);
fputs (" text_height:=max(text_height,ht[dec_num]+dp[dec_num]);\n", outfile);
fputs (" fi\n", outfile);
fputs (" endfor\n", outfile);
fputs (" if rot=90:\n", outfile);
fputs (" if justification=1: ynext:=ystart;\n", outfile);
fputs (" elseif justification=2: ynext:=round(ystart-text_width/2);\n", outfile);
fputs (" else: ynext:=round(ystart-text_width);\n", outfile);
fputs (" fi\n", outfile);
fputs (" xnext:=xstart+text_height/2;\n", outfile);
fputs (" else:\n", outfile);
fputs (" if justification=1: xnext:=xstart;\n", outfile);
fputs (" elseif justification=2: xnext:=round(xstart-text_width/2);\n", outfile);
fputs (" else: xnext:=round(xstart-text_width);\n", outfile);
fputs (" fi\n", outfile);
fputs (" ynext:=ystart-text_height/2;\n", outfile);
fputs (" fi\n", outfile);
fputs (" for ind:=0 step 1 until length(ts)-1:\n", outfile);
fputs (" dec_num:=ASCII substring (ind,ind+1) of ts;\n", outfile);
fputs (" if unknown r[dec_num]: dec_num:=32; fi\n", outfile);
fputs (" if dec_num=32: \n", outfile);
fputs (" xnext:=xnext+wd[65]*cosd rot;\n", outfile);
fputs (" ynext:=ynext+wd[65]*sind rot;\n", outfile);
fputs (" elseif dec_num>=0: \n", outfile);
fputs (" currentpicture:=currentpicture+r[dec_num] shifted(xnext,ynext)\n", outfile);
fputs (" rotatedaround ((xnext,ynext),rot); \n", outfile);
fputs (" xnext:=xnext+wd[dec_num]*cosd rot;\n", outfile);
fputs (" ynext:=ynext+wd[dec_num]*sind rot;\n", outfile);
fputs (" fi\n", outfile);
fputs (" endfor\n", outfile);
fputs (" endgroup \n", outfile);
fputs ("enddef;\n", outfile);
fputs ("\ndef endchar =\n", outfile);
fputs (" r[charcode]:=currentpicture;\n", outfile);
fputs (" wd[charcode]:=w;ht[charcode]:=h;dp[charcode]:=d;\n", outfile);
fputs (" message \"Picture of charcode no.\" & decimal charcode;\n", outfile);
fputs (" endgroup;\n", outfile);
fputs ("enddef;\n", outfile);
fputs ("let endchar_ = endchar;\n", outfile);
fputs ("let generate = relax;\n", outfile);
fputs ("let roman = relax;\n", outfile);
fputs ("input cmr10.mf\n", outfile);
fputs ("if ligs>1: font_coding_scheme:=\"TeX text\";\n", outfile);
fputs (" spanish_shriek=oct\"074\"; spanish_query=oct\"076\";\n", outfile);
fputs ("else: font_coding_scheme:=\n", outfile);
fputs (" if ligs=0: \"TeX typewriter text\"\n", outfile);
fputs (" else: \"TeX text without f-ligatures\" fi;\n", outfile);
fputs (" spanish_shriek=oct\"016\"; spanish_query=oct\"017\"; fi\n", outfile);
fputs ("font_setup;\n", outfile);
fputs ("input romanu.mf %Roman uppercase.\n", outfile);
fputs ("input romanl.mf %Roman lowerrcase.\n", outfile);
fputs ("input greeku.mf %Greek uppercase.\n", outfile);
fputs ("input romand.mf %Numerals.\n", outfile);
fputs ("input romanp.mf %Ampersand, question marks, currency sign.\n", outfile);
fputs ("input romspl.mf %Lowercase specials (dotless \\i, ligature \\ae, etc.)\n", outfile);
fputs ("input romspu.mf %Uppercase specials (\\AE, \\OE, \\O)\n", outfile);
fputs ("input punct.mf %Punctuation symbols.\n", outfile);
fputs ("\nminus=ASCII\"-\"; cmchar \"Minus sign\";\n", outfile);
fputs ("beginarithchar(minus); \n", outfile);
fputs (" pickup rule.nib;\n", outfile);
fputs (" lft x1=hround 1.5u-eps;\n", outfile);
fputs (" x2=w-x1; y1=y2=math_axis;\n", outfile);
fputs (" draw z1--z2; % bar\n", outfile);
fputs (" labels(1,2); \n", outfile);
fputs ("endchar;\n", outfile);
fputs ("\ncmchar \"Period\";\n", outfile);
fputs (" numeric dot_diam#; dot_diam#:=if monospace: 5/4 fi\\ dot_size#;\n", outfile);
fputs (" define_whole_blacker_pixels(dot_diam);\n", outfile);
fputs (" beginchar(\".\",5u#,dot_diam#,0);\n", outfile);
fputs (" adjust_fit(0,0); pickup fine.nib;\n", outfile);
fputs (" pos1(dot_diam,0); pos2(dot_diam,90);\n", outfile);
fputs (" lft x1l=hround(.5w-.5dot_diam); bot y2l=0; z1=z2; dot(1,2); % dot\n", outfile);
fputs (" penlabels(1,2);\n", outfile);
fputs ("endchar;\n", outfile);
fputs ("\ndef endchar =\n", outfile);
fputs (" % Next line should probably be removed if CM base is used\n", outfile);
fputs (" l:=0; r:=w;\n", outfile);
fputs (" %Include the next two lines if you want to\n", outfile);
fputs (" %rotate the picture 90 deg.(Portrait to Landscape)\n", outfile);
fputs (" %currentpicture:=currentpicture rotated 90 shifted (h,0);\n", outfile);
fputs (" %tmp:=charht; charht:=charwd; charwd:=tmp;\n", outfile);
fputs (" scantokens extra_endchar;\n", outfile);
fputs (" if proofing>0: makebox(proofrule); fi\n", outfile);
fputs (" chardx:=w;\n", outfile);
fputs (" shipit;\n", outfile);
fputs (" if displaying>0: makebox(screenrule); showit; fi\n", outfile);
fputs (" endgroup \n", outfile);
fputs ("enddef;\n", outfile);
fputs ("let endchar_ = endchar;\n", outfile);
fputs ("let generate = input;\n", outfile);
fputs ("let roman = roman;\n", outfile);
fputs ("\n\nfont_identifier:=\"GNUPLOT\";\n", outfile);
/* font_size must be bigger than em#/16 by METAFONT rules.
* Therefore make it pretty big so big figures will be
* handled correctly. Setting font_size to 72pt# lets us
* handle characters up to 15.94 by 15.94 inches. */
fputs ("font_size 72pt#;\n", outfile);
fputs ("th#=0.4pt#; define_whole_pixels(th);\n", outfile);
fputs ("\npath arrowhead;\n", outfile);
fputs ("arrowhead = (-7pt,-2pt){dir30}..(-6pt,0pt)..", outfile);
fputs ("{dir150}(-7pt,2pt) &\n", outfile);
fputs (" (-7pt,2pt)--(0pt,0pt)--(-7pt,-2pt) & cycle;\n", outfile);
}
int MF_graphics ()
{
register struct termentry *t = &term_tbl[term];
fprintf (outfile, "\n\nbeginchar(%d,%gin#,%gin#,0);\n",
MF_char_code, MF_xsize, MF_ysize);
MF_char_code++;
fprintf (outfile, "a:=w/%d;b:=h/%d;\n", t->xmax, t->ymax);
MF_picked_up_pen = 0;
}
int MF_text ()
{
fprintf (outfile, "endchar;\n");
}
int MF_justify_text (mode)
enum JUSTIFY mode;
{
MF_justify = mode;
return TRUE;
}
int MF_text_angle (ang)
int ang;
{
if (ang > 0) MF_ang = 90;
else MF_ang = 0;
return TRUE;
}
int MF_linetype (linetype)
int linetype;
{
if (linetype >=8) linetype %= 8;
linetype += 2;
/* Only output change in pens if it actually affects the pen used */
if ((MF_lines[linetype].thickness != MF_lines[MF_line_type].thickness) ||
(!MF_picked_up_pen)) {
fprintf (outfile, "pickup pencircle scaled %gth;\n",
MF_lines[linetype].thickness);
MF_picked_up_pen = 1;
}
MF_line_type = linetype;
MF_dash_index = 0;
MF_dist_left = MF_lines[MF_line_type].dashlen[MF_dash_index];
MF_is_solid = MF_lines[MF_line_type].solid;
}
int MF_scale (xs, ys)
double xs, ys;
{
struct termentry *t = &term_tbl[term];
t->xmax = (unsigned int) (MF_XMAX * xs);
t->ymax = (unsigned int) (MF_YMAX * ys);
MF_xsize = MF_XSIZE * xs;
MF_ysize = MF_YSIZE * ys;
return TRUE;
}
int MF_move (x, y)
unsigned int x, y;
{
MF_last_x = x;
MF_last_y = y;
MF_dash_index = 0;
MF_dist_left = MF_lines[MF_line_type].dashlen[MF_dash_index];
}
int MF_vector (x, y)
unsigned int x, y;
{
double sqrt(), floor();
if (MF_is_solid) {
if (x == MF_last_x && y == MF_last_y)
fprintf (outfile, "drawdot (%da,%db);\n", x, y);
else
fprintf (outfile, "draw (%da,%db)--(%da,%db);\n",
MF_last_x, MF_last_y, x, y);
} else {
double dist_to_go, delta_x, delta_y, inc_x, inc_y;
double last_x_d, last_y_d, next_x_d, next_y_d;
unsigned int next_x, next_y;
if (x == MF_last_x && y == MF_last_y) {
if (! (MF_dash_index & 1))
fprintf (outfile, "drawdot (%da,%db);\n", x, y);
} else {
last_x_d = MF_last_x;
last_y_d = MF_last_y;
delta_x = x - last_x_d;
delta_y = y - last_y_d;
dist_to_go = sqrt (delta_x * delta_x + delta_y * delta_y);
inc_x = delta_x / dist_to_go;
inc_y = delta_y / dist_to_go;
while (MF_dist_left < dist_to_go) {
next_x_d = last_x_d + inc_x * MF_dist_left;
next_y_d = last_y_d + inc_y * MF_dist_left;
next_x = floor (next_x_d + 0.5);
next_y = floor (next_y_d + 0.5);
/* MF_dash_index & 1 == 0 means: draw a line; otherwise just move */
if (! (MF_dash_index & 1))
fprintf (outfile, "draw (%da,%db)--(%da,%db);\n",
MF_last_x, MF_last_y, next_x, next_y);
MF_last_x = next_x;
MF_last_y = next_y;
last_x_d = next_x_d;
last_y_d = next_y_d;
dist_to_go -= MF_dist_left;
MF_dash_index = (MF_dash_index + 1) & 3;
MF_dist_left = MF_lines[MF_line_type].dashlen[MF_dash_index];
}
delta_x = x - last_x_d;
delta_y = y - last_y_d;
MF_dist_left -= sqrt (delta_x * delta_x + delta_y * delta_y);
if (! (MF_dash_index & 1)) {
if (x == MF_last_x && y == MF_last_y)
fprintf (outfile, "drawdot (%da,%db);\n", x, y);
else
fprintf (outfile, "draw (%da,%db)--(%da,%db);\n",
MF_last_x, MF_last_y, x, y);
}
}
}
MF_last_x = x;
MF_last_y = y;
}
int MF_arrow (sx, sy, ex, ey, head)
unsigned int sx, sy, ex, ey;
TBOOLEAN head;
{
int delta_x, delta_y;
MF_move (sx, sy);
MF_vector (ex, ey);
if (head) {
delta_x = ex - sx;
delta_y = ey - sy;
fprintf (outfile, "fill arrowhead rotated angle(%d,%d) shifted (%da,%db);\n",
delta_x, delta_y, ex, ey);
}
}
int MF_put_text (x, y, str)
unsigned int x, y;
char *str;
{
int i, j;
for (i = 0; i < strlen (str); i++)
if (str[i] == '"')
str[i] = '\''; /* Replace " with ' */
switch (MF_justify) {
case LEFT:
j = 1;
break;
case CENTRE:
j = 2;
break;
case RIGHT:
j = 3;
break;
}
fprintf (outfile, "put_text(\"%s\",%da,%db,%d,%d);\n",
str, x, y, MF_ang, j);
}
int MF_reset ()
{
fprintf (outfile, "end.\n");
}